/*
 * 作者: 侯晓宇
 * 时间: 2017-02-16
 * 说明：
 * Copyright (c) 2016-2017 中研沃兮
 */

define(function(require) {

	require("jquery");

	var c = require('app/utils/CommonUtils');
	var EventUtils = require('app/utils/EventUtils');
	var appInfo = require('app/AppInfo');
	var WebSocketUtils = require('app/utils/WebSocketUtils');
	var UserInfoUtils = require('app/utils/UserInfoUtils');
	var s = {};
	
	var userinfo = UserInfoUtils.getLoginedUser();
	
	s.sendVerifyCode = function(content){
	
		var subscribe_pattern = "/ws/private/ppt/key/"+content;
		//注册监听pattern
		WebSocketUtils.subscribe(subscribe_pattern, function(data_pack){
			var data = JSON.parse(data_pack.body);
			api.alert({
				title: "授权成功",
				msg: '请使用PC端浏览器上传PPT',
	    		buttons: ['确定']
	        },function(ret,err){
	        	if(ret.buttonIndex == 1){ //确定
	        		location.reload();
	        	}
	        });
		});

		var param = {};
		
		var endpointurl = appInfo.serverbase + "/appchat_websocket";
		 
		WebSocketUtils.connect(endpointurl, param,function(){
			
			var body = {};
			body.type = "auth";
			body.headimgurl = userinfo.userheadimgurl;
			body.name = userinfo.username;
			body.userid = userinfo.userid;
	
			WebSocketUtils.send("/appchat/private/ppt/key/"+content, body);
			
		},function(){
		//如果断开连接，则进行重连
		
		});
			
	
	
	
	}
	

	return s;
});
